package com.zx.mobile.service.proxy;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zx.map.service.model.CreditRepayInfoModel;
import com.zx.map.service.model.CreditRepayLogModel;
import com.zx.mobile.domain.MobileUserDomain;
import com.zx.mobile.domain.creditrepay.CreditSelectDomain;

public class CreditRepayProxy {

	/**
	 * 信用卡还款展示前处理
	 * 
	 * @param list
	 * @return
	 */
	public static List<CreditRepayInfoModel> transformCreditRepay(
			List<CreditRepayInfoModel> list) {
		for (CreditRepayInfoModel oo : list) {
			StringBuffer tempName = new StringBuffer("");
			StringBuffer tempAccount = new StringBuffer("");
			if (null != oo.getCardName()) {
				for (int i = 0; i < oo.getCardName().length(); i++) {
					if (i >= 1) {
						tempName.append("*");
					} else {
						tempName.append(oo.getCardName().charAt(i));
					}
				}
				oo.setShortName(tempName.toString());
			}

			for (int j = 0; oo.getBankAccount()!=null&&j < oo.getBankAccount().length(); j++) {
				if (j >= 4 && j < oo.getBankAccount().length() - 4) {
					tempAccount.append("*");
				} else {
					tempAccount.append(oo.getBankAccount().charAt(j));
				}
			}
			oo.setShortCardNo(tempAccount.toString());
			if(oo.getBankAccount()!=null){
				oo.setLastCardNo(oo.getBankAccount().substring(
						oo.getBankAccount().length() - 4));
			}
		}
		return list;
	}

	/**
	 * 模态转换
	 * 
	 * @param user
	 * @param creditSelectDomain
	 * @return
	 */
	public static CreditRepayInfoModel transformToCreditRepay(
			MobileUserDomain user, CreditSelectDomain creditSelectDomain) {
		// 保存信用卡信息
		CreditRepayInfoModel creditRepayInfoModel = new CreditRepayInfoModel();
		creditRepayInfoModel.setBankAccount(creditSelectDomain.getCardNo());
		creditRepayInfoModel.setBankCity("");
		creditRepayInfoModel.setBankCode(creditSelectDomain.getBankCode());
		creditRepayInfoModel.setBankName(creditSelectDomain.getBankName());
		creditRepayInfoModel.setBankProvince("");
		creditRepayInfoModel.setCreateDate(new Date());
		creditRepayInfoModel.setCardName(creditSelectDomain.getCardName());
		creditRepayInfoModel.setMerchantId(user.getMerchantInfoDetailModel()
				.getMerchantId());
		creditRepayInfoModel.setMerSysAccount(user.getMerchantInfoDetailModel()
				.getSysAccount());
		creditRepayInfoModel.setNotifyFlag(creditSelectDomain.getNotifyFlag());
		creditRepayInfoModel.setNotifyDate(creditSelectDomain.getNotifyDate());
		creditRepayInfoModel.setStatus("S");
		return creditRepayInfoModel;
	}
	/**
	 * 信用卡还款账单展示前处理
	 * 
	 * @param list
	 * @return
	 */
	public static Map<String,List> transformCreditRepayLog(
			List<CreditRepayLogModel> list) {
		Map<String,List> monthMap = new HashMap();
		for (CreditRepayLogModel oo : list) {
			StringBuffer tempName = new StringBuffer("");
			StringBuffer tempAccount = new StringBuffer("");

			for (int j = 0; oo.getBankAccount()!=null&&j < oo.getBankAccount().length(); j++) {
				if (j >= 4 && j < oo.getBankAccount().length() - 4) {
					tempAccount.append("*");
				} else {
					tempAccount.append(oo.getBankAccount().charAt(j));
				}
			}
			oo.setShortCardNo(tempAccount.toString());
			if(oo.getBankAccount()!=null){
				oo.setLastCardNo(oo.getBankAccount().substring(
						oo.getBankAccount().length() - 4));
			}
			if(oo.getRepayDay()!=null){
				oo.setShortTime(oo.getRepayDay().substring(4, 6)+"-"+oo.getRepayDay().substring(6, 8));
				String shortMonth = oo.getRepayDay().substring(0, 4)+"年"+Integer.valueOf(oo.getRepayDay().substring(4, 6))+"月";
				if(monthMap.get(shortMonth)==null){
					List addList = new ArrayList();
					addList.add(oo);
					monthMap.put(shortMonth,addList);
				}else{
					List addList = monthMap.get(shortMonth);
					addList.add(oo);
				}
				oo.setShortTime(oo.getRepayDay().substring(4, 6)+"-"+oo.getRepayDay().substring(6, 8));
			}
		}
		return monthMap;
	}
}
